home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / adpcm / sgidaudio.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  1KB  |  71 lines

  1. /*
  2. ** sgidaudio - Simple AIFF file decompressor.
  3. **
  4. ** Needs libaf, which is in the Digital Media developers option.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <audio.h>
  9. #include <audiofile.h>
  10. #include "adpcm.h"
  11.  
  12. #define NFRAMES 8000
  13.  
  14. struct adpcm_state astate;
  15. char ibuf[NFRAMES/2];
  16. short obuf[NFRAMES];
  17.  
  18. main(argc, argv)
  19.     int argc;
  20.     char **argv;
  21. {
  22.     AFfilehandle af;
  23.     AFfilesetup afsetup;
  24.     FILE *of;
  25.     long fmt, width;
  26.     long count;
  27.     int outindex;
  28.     
  29.     if ( argc < 2 || argc > 3 ) {
  30.     fprintf(stderr, "Usage: %s [adpcmfile] aifffile\n", argv[0]);
  31.     exit(1);
  32.     }
  33.     /*
  34.     ** Open input file
  35.     */
  36.     if ( argc == 3 ) {
  37.     if ( (of = fopen(argv[1], "r")) == NULL ) {
  38.         perror(argv[1]);
  39.         exit(1);
  40.     }
  41.     outindex = 2;
  42.     } else {
  43.     of = stdin;
  44.     outindex = 1;
  45.     }
  46.     /*
  47.     ** Open output file
  48.     */
  49.     afsetup = AFnewfilesetup();
  50.     AFinitchannels(afsetup, AF_DEFAULT_TRACK, 1);
  51.     AFinitrate(afsetup, AF_DEFAULT_TRACK, 8000.0);
  52.     AFinitsampfmt(afsetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
  53.     if ( (af = AFopenfile(argv[outindex], "w", afsetup)) == 0 ) {
  54.     perror(argv[outindex]);
  55.     exit(1);
  56.     }
  57.     /*
  58.     ** Copy loop
  59.     */
  60.     while (1) {
  61.     count = fread(ibuf, 1, NFRAMES/2, of);
  62.     if ( count <= 0 ) break;
  63.     count = count*2;
  64.     adpcm_decoder(ibuf, obuf, count, &astate);
  65.     AFwriteframes(af, AF_DEFAULT_TRACK, obuf, count);
  66.     }
  67.     fclose(of);
  68.     AFclosefile(af);
  69.     exit(0);
  70. }
  71.